package expressions;

/**
 * An expression representing a constant value which is returned when the
 * expression is evaluated.
 * 
 */
public abstract class Constant<T> extends Expression<T>
{
    private T value;

    /**
     * Constructs a Constant expression from the token that represented it in
     * the input.
     */
    public Constant(String token)
    {
        value = parseToken(token);
    }

    /**
     * This method is called during construction and should interpret a string
     * that represents a constant of type T.
     * 
     * @param token
     *            The token that represented this constant in the input
     * @return a T value corresponding to the String.
     */
    protected abstract T parseToken(String token);

    @Override
    public T evaluate(IContext<T> context)
    {
        return value;
    }
}
